﻿
namespace AB.ServiceDirectory.Design.GovernmentOfficeRegion
{
    using System;
    using Dao.DataFilters;

    public partial class ListGor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var filter = new GovOfficeRegionFilter();
                ViewState["filter"] = filter;
            }
        }

        protected void ObjectDataSourceGor_Selecting(object sender, System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs e)
        {
            var filter = ViewState["filter"] as GovOfficeRegionFilter;
            e.InputParameters["filter"] = filter;
        }

        protected void FilterByLetters_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e)
        {
            var filter = ViewState["filter"] as GovOfficeRegionFilter;
            if (filter == null)
            {
                return;
            }

            switch (e.CommandName)
            {
                case "09":
                    filter.BeginningLetter = new[] { "0", "9" };
                    break;
                case "ae":
                    filter.BeginningLetter = new[] { "a", "b", "c", "d", "e" };
                    break;
                case "fj":
                    filter.BeginningLetter = new[] { "f", "g", "h", "j", "i" };
                    break;
                case "kn":
                    filter.BeginningLetter = new[] { "k", "l", "m", "n" };
                    break;
                case "or":
                    filter.BeginningLetter = new[] { "o", "p", "q", "r" };
                    break;
                case "sv":
                    filter.BeginningLetter = new[] { "s", "t", "u", "v" };
                    break;
                case "wz":
                    filter.BeginningLetter = new[] { "w", "x", "y", "z" };
                    break;
                default:
                    filter.BeginningLetter = null;
                    break;
            }

            this.GridViewGor.DataBind();
        }

        protected void CheckBoxInActive_CheckedChanged(object sender, EventArgs e)
        {
            var filter = ViewState["filter"] as GovOfficeRegionFilter;
            if (filter != null) filter.IncludeInactive = CheckBoxInActive.Checked;
            this.GridViewGor.DataBind();
        }
    }
}